package com.my.kq.controller;

import com.my.kq.entity.Employee;
import com.my.kq.entity.Leave;
import com.my.kq.service.EmployeeService;
import com.my.kq.service.LeaveService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LookLookServlet")
public class LookLookServlet extends HttpServlet {
    public LeaveService leaveService=new LeaveService();
    public EmployeeService employeeService=new EmployeeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            //查询详细信息
            req.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            String id = req.getParameter("id");
            //id获得Leave对象数据     然后从中获得EmployeeNumber   在查Employee对象数据获得name    双标查询
            Leave leave = leaveService.getLeaveById(Integer.parseInt(id));
            Integer employeeNumber = leave.getEmployeeNumber();
            Employee employee = employeeService.getEmployee(employeeNumber);
            leave.setName(employee.getName());
            req.setAttribute("leave",leave);
            req.getRequestDispatcher("jsp/admin/leave_detail.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
